home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / gas / config / tc-i860.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-13  |  30.5 KB  |  1,322 lines

  1. /* tc-i860.c -- Assemble for the I860
  2.    Copyright (C) 1989, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "as.h"
  21.  
  22. #include "opcode/i860.h"
  23.  
  24. void md_begin ();
  25. void md_number_to_chars ();
  26. void md_assemble ();
  27. char *md_atof ();
  28. void md_convert_frag ();
  29. void md_create_short_jump ();
  30. void md_create_long_jump ();
  31. int md_estimate_size_before_relax ();
  32. void md_number_to_imm ();
  33. void md_number_to_disp ();
  34. void md_number_to_field ();
  35. void md_ri_to_chars ();
  36. static void i860_ip ();
  37. /* void emit_machine_reloc(); */
  38.  
  39. const int md_reloc_size = sizeof (struct relocation_info);
  40.  
  41. /* void (*md_emit_relocations)() = emit_machine_reloc; */
  42.  
  43. const relax_typeS md_relax_table[] =
  44. {0};
  45.  
  46. /* handle of the OPCODE hash table */
  47. static struct hash_control *op_hash = NULL;
  48.  
  49. static void s_dual (), s_enddual ();
  50. static void s_atmp ();
  51.  
  52. const pseudo_typeS
  53.   md_pseudo_table[] =
  54. {
  55.   {"dual", s_dual, 4},
  56.   {"enddual", s_enddual, 4},
  57.   {"atmp", s_atmp, 4},
  58.   {NULL, 0, 0},
  59. };
  60.  
  61. int md_short_jump_size = 4;
  62. int md_long_jump_size = 4;
  63.  
  64. /* This array holds the chars that always start a comment.  If the
  65.    pre-processor is disabled, these aren't very useful */
  66. const char comment_chars[] = "!/";    /* JF removed '|' from comment_chars */
  67.  
  68. /* This array holds the chars that only start a comment at the beginning of
  69.    a line.  If the line seems to have the form '# 123 filename'
  70.    .line and .file directives will appear in the pre-processed output */
  71. /* Note that input_file.c hand checks for '#' at the beginning of the
  72.    first line of the input file.  This is because the compiler outputs
  73.    #NO_APP at the beginning of its output. */
  74. /* Also note that comments like this one will always work. */
  75. const char line_comment_chars[] = "#/";
  76.  
  77. const char line_separator_chars[] = "";
  78.  
  79. /* Chars that can be used to separate mant from exp in floating point nums */
  80. const char EXP_CHARS[] = "eE";
  81.  
  82. /* Chars that mean this number is a floating point constant */
  83. /* As in 0f12.456 */
  84. /* or    0d1.2345e12 */
  85. const char FLT_CHARS[] = "rRsSfFdDxXpP";
  86.  
  87. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  88.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  89.    but nothing is ideal around here.
  90.    */
  91. int size_reloc_info = sizeof (struct relocation_info);
  92.  
  93. static unsigned char octal[256];
  94. #define isoctal(c)  octal[c]
  95. static unsigned char toHex[256];
  96.  
  97. struct i860_it
  98.   {
  99.     char *error;
  100.     unsigned long opcode;
  101.     struct nlist *nlistp;
  102.     expressionS exp;
  103.     int pcrel;
  104.     enum expand_type expand;
  105.     enum highlow_type highlow;
  106.     enum reloc_type reloc;
  107.   } the_insn;
  108.  
  109. #if __STDC__ == 1
  110.  
  111. static void print_insn (struct i860_it *insn);
  112. static int getExpression (char *str);
  113.  
  114. #else /* not __STDC__ */
  115.  
  116. static void print_insn ();
  117. static int getExpression ();
  118.  
  119. #endif /* not __STDC__ */
  120.  
  121. static char *expr_end;
  122. static char last_expand;    /* error if expansion after branch */
  123.  
  124. enum dual
  125. {
  126.   DUAL_OFF = 0, DUAL_ON, DUAL_DDOT, DUAL_ONDDOT,
  127. };
  128. static enum dual dual_mode = DUAL_OFF;    /* dual-instruction mode */
  129.  
  130. static void
  131. s_dual ()            /* floating point instructions have dual set */
  132. {
  133.   dual_mode = DUAL_ON;
  134. }
  135.  
  136. static void
  137. s_enddual ()            /* floating point instructions have dual set */
  138. {
  139.   dual_mode = DUAL_OFF;
  140. }
  141.  
  142. static int atmp = 31;        /* temporary register for pseudo's */
  143.  
  144. static void
  145. s_atmp ()
  146. {
  147.   register int temp;
  148.   if (strncmp (input_line_pointer, "sp", 2) == 0)
  149.     {
  150.       input_line_pointer += 2;
  151.       atmp = 2;
  152.     }
  153.   else if (strncmp (input_line_pointer, "fp", 2) == 0)
  154.     {
  155.       input_line_pointer += 2;
  156.       atmp = 3;
  157.     }
  158.   else if (strncmp (input_line_pointer, "r", 1) == 0)
  159.     {
  160.       input_line_pointer += 1;
  161.       temp = get_absolute_expression ();
  162.       if (temp >= 0 && temp <= 31)
  163.     atmp = temp;
  164.       else
  165.     as_bad ("Unknown temporary pseudo register");
  166.     }
  167.   else
  168.     {
  169.       as_bad ("Unknown temporary pseudo register");
  170.     }
  171.   demand_empty_rest_of_line ();
  172. }
  173.  
  174. /* This function is called once, at assembler startup time.  It should
  175.    set up all the tables, etc. that the MD part of the assembler will need.  */
  176. void
  177. md_begin ()
  178. {
  179.   register char *retval = NULL;
  180.   int lose = 0;
  181.   register unsigned int i = 0;
  182.  
  183.   op_hash = hash_new ();
  184.  
  185.   while (i < NUMOPCODES)
  186.     {
  187.       const char *name = i860_opcodes[i].name;
  188.       retval = hash_insert (op_hash, name, &i860_opcodes[i]);
  189.       if (retval != NULL)
  190.     {
  191.       fprintf (stderr, "internal error: can't hash `%s': %s\n",
  192.            i860_opcodes[i].name, retval);
  193.       lose = 1;
  194.     }
  195.       do
  196.     {
  197.       if (i860_opcodes[i].match & i860_opcodes[i].lose)
  198.         {
  199.           fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
  200.                i860_opcodes[i].name, i860_opcodes[i].args);
  201.           lose = 1;
  202.         }
  203.       ++i;
  204.     }
  205.       while (i < NUMOPCODES
  206.          && !strcmp (i860_opcodes[i].name, name));
  207.     }
  208.  
  209.   if (lose)
  210.     as_fatal ("Broken assembler.  No assembly attempted.");
  211.  
  212.   for (i = '0'; i < '8'; ++i)
  213.     octal[i] = 1;
  214.   for (i = '0'; i <= '9'; ++i)
  215.     toHex[i] = i - '0';
  216.   for (i = 'a'; i <= 'f'; ++i)
  217.     toHex[i] = i + 10 - 'a';
  218.   for (i = 'A'; i <= 'F'; ++i)
  219.     toHex[i] = i + 10 - 'A';
  220. }
  221.  
  222. void
  223. md_assemble (str)
  224.      char *str;
  225. {
  226.   char *toP;
  227.   int rsd;
  228.   int no_opcodes = 1;
  229.   int i;
  230.   struct i860_it pseudo[3];
  231.  
  232.   assert (str);
  233.   i860_ip (str);
  234.  
  235.   /* check for expandable flag to produce pseudo-instructions */
  236.   if (the_insn.expand != 0 && the_insn.highlow == NO_SPEC)
  237.     {
  238.       for (i = 0; i < 3; i++)
  239.     pseudo[i] = the_insn;
  240.  
  241.       switch (the_insn.expand)
  242.     {
  243.  
  244.     case E_DELAY:
  245.       no_opcodes = 1;
  246.       break;
  247.  
  248.     case E_MOV:
  249.       if (the_insn.exp.X_add_symbol == NULL &&
  250.           the_insn.exp.X_op_symbol == NULL &&
  251.           (the_insn.exp.X_add_number < (1 << 15) &&
  252.            the_insn.exp.X_add_number >= -(1 << 15)))
  253.         break;
  254.       /* or l%const,r0,ireg_dest */
  255.       pseudo[0].opcode = (the_insn.opcode & 0x001f0000) | 0xe4000000;
  256.       pseudo[0].highlow = PAIR;
  257.       /* orh h%const,ireg_dest,ireg_dest */
  258.       pseudo[1].opcode = (the_insn.opcode & 0x03ffffff) | 0xec000000 |
  259.         ((the_insn.opcode & 0x001f0000) << 5);
  260.       pseudo[1].highlow = HIGH;
  261.       no_opcodes = 2;
  262.       break;
  263.  
  264.     case E_ADDR:
  265.       if (the_insn.exp.X_add_symbol == NULL &&
  266.           the_insn.exp.X_op_symbol == NULL)
  267.         break;
  268.       /* orh ha%addr_expr,r0,r31 */
  269.       pseudo[0].opcode = 0xec000000 | (atmp << 16);
  270.       pseudo[0].highlow = HIGHADJ;
  271.       pseudo[0].reloc = LOW0;    /* must overwrite */
  272.       /* l%addr_expr(r31),ireg_dest */
  273.       pseudo[1].opcode = (the_insn.opcode & ~0x003e0000) | (atmp << 21);
  274.       pseudo[1].highlow = PAIR;
  275.       no_opcodes = 2;
  276.       break;
  277.  
  278.     case E_U32:        /* 2nd version emulates Intel as, not doc. */
  279.       if (the_insn.exp.X_add_symbol == NULL &&
  280.           the_insn.exp.X_op_symbol == NULL &&
  281.           (the_insn.exp.X_add_number < (1 << 16) &&
  282.            the_insn.exp.X_add_number >= 0))
  283.         break;
  284.       /* $(opcode)h h%const,ireg_src2,ireg_dest
  285.                pseudo[0].opcode = (the_insn.opcode & 0xf3ffffff) | 0x0c000000; */
  286.       /* $(opcode)h h%const,ireg_src2,r31 */
  287.       pseudo[0].opcode = (the_insn.opcode & 0xf3e0ffff) | 0x0c000000 |
  288.         (atmp << 16);
  289.       pseudo[0].highlow = HIGH;
  290.       /* $(opcode) l%const,ireg_dest,ireg_dest
  291.                pseudo[1].opcode = (the_insn.opcode & 0xf01f0000) | 0x04000000 |
  292.                ((the_insn.opcode & 0x001f0000) << 5); */
  293.       /* $(opcode) l%const,r31,ireg_dest */
  294.       pseudo[1].opcode = (the_insn.opcode & 0xf01f0000) | 0x04000000 |
  295.         (atmp << 21);
  296.       pseudo[1].highlow = PAIR;
  297.       no_opcodes = 2;
  298.       break;
  299.  
  300.     case E_AND:        /* 2nd version emulates Intel as, not doc. */
  301.       if (the_insn.exp.X_add_symbol == NULL &&
  302.           the_insn.exp.X_op_symbol == NULL &&
  303.           (the_insn.exp.X_add_number < (1 << 16) &&
  304.            the_insn.exp.X_add_number >= 0))
  305.         break;
  306.       /* andnot h%const,ireg_src2,ireg_dest
  307.                pseudo[0].opcode = (the_insn.opcode & 0x03ffffff) | 0xd4000000; */
  308.       /* andnot h%const,ireg_src2,r31 */
  309.       pseudo[0].opcode = (the_insn.opcode & 0x03e0ffff) | 0xd4000000 |
  310.         (atmp << 16);
  311.       pseudo[0].highlow = HIGH;
  312.       pseudo[0].exp.X_add_number = -1 - the_insn.exp.X_add_number;
  313.       /* andnot l%const,ireg_dest,ireg_dest
  314.                pseudo[1].opcode = (the_insn.opcode & 0x001f0000) | 0xd4000000 |
  315.                ((the_insn.opcode & 0x001f0000) << 5); */
  316.       /* andnot l%const,r31,ireg_dest */
  317.       pseudo[1].opcode = (the_insn.opcode & 0x001f0000) | 0xd4000000 |
  318.         (atmp << 21);
  319.       pseudo[1].highlow = PAIR;
  320.       pseudo[1].exp.X_add_number = -1 - the_insn.exp.X_add_number;
  321.       no_opcodes = 2;
  322.       break;
  323.  
  324.     case E_S32:
  325.       if (the_insn.exp.X_add_symbol == NULL &&
  326.           the_insn.exp.X_op_symbol == NULL &&
  327.           (the_insn.exp.X_add_number < (1 << 15) &&
  328.            the_insn.exp.X_add_number >= -(1 << 15)))
  329.         break;
  330.       /* orh h%const,r0,r31 */
  331.       pseudo[0].opcode = 0xec000000 | (atmp << 16);
  332.       pseudo[0].highlow = HIGH;
  333.       /* or l%const,r31,r31 */
  334.       pseudo[1].opcode = 0xe4000000 | (atmp << 21) | (atmp << 16);
  335.       pseudo[1].highlow = PAIR;
  336.       /* r31,ireg_src2,ireg_dest */
  337.       pseudo[2].opcode = (the_insn.opcode & ~0x0400ffff) | (atmp << 11);
  338.       pseudo[2].reloc = NO_RELOC;
  339.       no_opcodes = 3;
  340.       break;
  341.  
  342.     default:
  343.       as_fatal ("failed sanity check.");
  344.     }
  345.  
  346.       the_insn = pseudo[0];
  347.       /* check for expanded opcode after branch or in dual */
  348.       if (no_opcodes > 1 && last_expand == 1)
  349.     as_warn ("Expanded opcode after delayed branch: `%s'", str);
  350.       if (no_opcodes > 1 && dual_mode != DUAL_OFF)
  351.     as_warn ("Expanded opcode in dual mode: `%s'", str);
  352.     }
  353.  
  354.   i = 0;
  355.   do
  356.     {                /* always produce at least one opcode */
  357.       toP = frag_more (4);
  358.       /* put out the opcode */
  359.       md_number_to_chars (toP, the_insn.opcode, 4);
  360.  
  361.       /* check for expanded opcode after branch or in dual */
  362.       last_expand = the_insn.pcrel;
  363.  
  364.       /* put out the symbol-dependent stuff */
  365.       if (the_insn.reloc != NO_RELOC)
  366.     {
  367.       fix_new (frag_now,    /* which frag */
  368.            (toP - frag_now->fr_literal),    /* where */
  369.            4,        /* size */
  370.            &the_insn.exp,
  371.            the_insn.pcrel,
  372.       /* merge bit fields into one argument */
  373.       (int) (((the_insn.highlow & 0x3) << 4) | (the_insn.reloc & 0xf)));
  374.     }
  375.       the_insn = pseudo[++i];
  376.     }
  377.   while (--no_opcodes > 0);
  378.  
  379. }
  380.  
  381. static void
  382. i860_ip (str)
  383.      char *str;
  384. {
  385.   char *s;
  386.   const char *args;
  387.   char c;
  388.   unsigned long i;
  389.   struct i860_opcode *insn;
  390.   char *argsStart;
  391.   unsigned long opcode;
  392.   unsigned int mask;
  393.   int match = 0;
  394.   int comma = 0;
  395.  
  396.  
  397.   for (s = str; islower (*s) || *s == '.' || *s == '3'; ++s)
  398.     ;
  399.   switch (*s)
  400.     {
  401.  
  402.     case '\0':
  403.       break;
  404.  
  405.     case ',':
  406.       comma = 1;
  407.  
  408.       /*FALLTHROUGH*/
  409.  
  410.     case ' ':
  411.       *s++ = '\0';
  412.       break;
  413.  
  414.     default:
  415.       as_fatal ("Unknown opcode: `%s'", str);
  416.     }
  417.  
  418.   if (strncmp (str, "d.", 2) == 0)
  419.     {                /* check for d. opcode prefix */
  420.       if (dual_mode == DUAL_ON)
  421.     dual_mode = DUAL_ONDDOT;
  422.       else
  423.     dual_mode = DUAL_DDOT;
  424.       str += 2;
  425.     }
  426.  
  427.   if ((insn = (struct i860_opcode *) hash_find (op_hash, str)) == NULL)
  428.     {
  429.       if (dual_mode == DUAL_DDOT || dual_mode == DUAL_ONDDOT)
  430.     str -= 2;
  431.       as_bad ("Unknown opcode: `%s'", str);
  432.       return;
  433.     }
  434.   if (comma)
  435.     {
  436.       *--s = ',';
  437.     }
  438.   argsStart = s;
  439.   for (;;)
  440.     {
  441.       opcode = insn->match;
  442.       memset (&the_insn, '\0', sizeof (the_insn));
  443.       the_insn.reloc = NO_RELOC;
  444.  
  445.       /*
  446.          * Build the opcode, checking as we go to make
  447.          * sure that the operands match
  448.          */
  449.       for (args = insn->args;; ++args)
  450.     {
  451.       switch (*args)
  452.         {
  453.  
  454.         case '\0':        /* end of args */
  455.           if (*s == '\0')
  456.         {
  457.           match = 1;
  458.         }
  459.           break;
  460.  
  461.         case '+':
  462.         case '(':        /* these must match exactly */
  463.         case ')':
  464.         case ',':
  465.         case ' ':
  466.           if (*s++ == *args)
  467.         continue;
  468.           break;
  469.  
  470.         case '#':        /* must be at least one digit */
  471.           if (isdigit (*s++))
  472.         {
  473.           while (isdigit (*s))
  474.             {
  475.               ++s;
  476.             }
  477.           continue;
  478.         }
  479.           break;
  480.  
  481.         case '1':        /* next operand must be a register */
  482.         case '2':
  483.         case 'd':
  484.           switch (*s)
  485.         {
  486.  
  487.         case 'f':    /* frame pointer */
  488.           s++;
  489.           if (*s++ == 'p')
  490.             {
  491.               mask = 0x3;
  492.               break;
  493.             }
  494.           goto error;
  495.  
  496.         case 's':    /* stack pointer */
  497.           s++;
  498.           if (*s++ == 'p')
  499.             {
  500.               mask = 0x2;
  501.               break;
  502.             }
  503.           goto error;
  504.  
  505.         case 'r':    /* any register */
  506.           s++;
  507.           if (!isdigit (c = *s++))
  508.             {
  509.               goto error;
  510.             }
  511.           if (isdigit (*s))
  512.             {
  513.               if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
  514.             {
  515.               goto error;
  516.             }
  517.             }
  518.           else
  519.             {
  520.               c -= '0';
  521.             }
  522.           mask = c;
  523.           break;
  524.  
  525.         default:    /* not this opcode */
  526.           goto error;
  527.         }
  528.           /*
  529.                  * Got the register, now figure out where
  530.                  * it goes in the opcode.
  531.                  */
  532.           switch (*args)
  533.         {
  534.  
  535.         case '1':
  536.           opcode |= mask << 11;
  537.           continue;
  538.  
  539.         case '2':
  540.           opcode |= mask << 21;
  541.           continue;
  542.  
  543.         case 'd':
  544.           opcode |= mask << 16;
  545.           continue;
  546.  
  547.         }
  548.           break;
  549.  
  550.         case 'e':        /* next operand is a floating point register */
  551.         case 'f':
  552.         case 'g':
  553.           if (*s++ == 'f' && isdigit (*s))
  554.         {
  555.           mask = *s++;
  556.           if (isdigit (*s))
  557.             {
  558.               mask = 10 * (mask - '0') + (*s++ - '0');
  559.               if (mask >= 32)
  560.             {
  561.               break;
  562.             }
  563.             }
  564.           else
  565.             {
  566.               mask -= '0';
  567.             }
  568.           switch (*args)
  569.             {
  570.  
  571.             case 'e':
  572.               opcode |= mask << 11;
  573.               continue;
  574.  
  575.             case 'f':
  576.               opcode |= mask << 21;
  577.               continue;
  578.  
  579.             case 'g':
  580.               opcode |= mask << 16;
  581.               if (dual_mode != DUAL_OFF)
  582.             opcode |= (1 << 9);    /* dual mode instruction */
  583.               if (dual_mode == DUAL_DDOT)
  584.             dual_mode = DUAL_OFF;
  585.               if (dual_mode == DUAL_ONDDOT)
  586.             dual_mode = DUAL_ON;
  587.               if ((opcode & (1 << 10)) && (mask == ((opcode >> 11) & 0x1f)))
  588.             as_warn ("Fsr1 equals fdest with Pipelining");
  589.               continue;
  590.             }
  591.         }
  592.           break;
  593.  
  594.         case 'c':        /* next operand must be a control register */
  595.           if (strncmp (s, "fir", 3) == 0)
  596.         {
  597.           opcode |= 0x0 << 21;
  598.           s += 3;
  599.           continue;
  600.         }
  601.           if (strncmp (s, "psr", 3) == 0)
  602.         {
  603.           opcode |= 0x1 << 21;
  604.           s += 3;
  605.           continue;
  606.         }
  607.           if (strncmp (s, "dirbase", 7) == 0)
  608.         {
  609.           opcode |= 0x2 << 21;
  610.           s += 7;
  611.           continue;
  612.         }
  613.           if (strncmp (s, "db", 2) == 0)
  614.         {
  615.           opcode |= 0x3 << 21;
  616.           s += 2;
  617.           continue;
  618.         }
  619.           if (strncmp (s, "fsr", 3) == 0)
  620.         {
  621.           opcode |= 0x4 << 21;
  622.           s += 3;
  623.           continue;
  624.         }
  625.           if (strncmp (s, "epsr", 4) == 0)
  626.         {
  627.           opcode |= 0x5 << 21;
  628.           s += 4;
  629.           continue;
  630.         }
  631.           break;
  632.  
  633.         case '5':        /* 5 bit immediate in src1 */
  634.           memset (&the_insn, '\0', sizeof (the_insn));
  635.           if (!getExpression (s))
  636.         {
  637.           s = expr_end;
  638.           if (the_insn.exp.X_add_number & ~0x1f)
  639.             as_bad ("5-bit immediate too large");
  640.           opcode |= (the_insn.exp.X_add_number & 0x1f) << 11;
  641.           memset (&the_insn, '\0', sizeof (the_insn));
  642.           the_insn.reloc = NO_RELOC;
  643.           continue;
  644.         }
  645.           break;
  646.  
  647.         case 'l':        /* 26 bit immediate, relative branch */
  648.           the_insn.reloc = BRADDR;
  649.           the_insn.pcrel = 1;
  650.           goto immediate;
  651.  
  652.         case 's':        /* 16 bit immediate, split relative branch */
  653.           /* upper 5 bits of offset in dest field */
  654.           the_insn.pcrel = 1;
  655.           the_insn.reloc = SPLIT0;
  656.           goto immediate;
  657.  
  658.         case 'S':        /* 16 bit immediate, split (st), aligned */
  659.           if (opcode & (1 << 28))
  660.         if (opcode & 0x1)
  661.           the_insn.reloc = SPLIT2;
  662.         else
  663.           the_insn.reloc = SPLIT1;
  664.           else
  665.         the_insn.reloc = SPLIT0;
  666.           goto immediate;
  667.  
  668.         case 'I':        /* 16 bit immediate, aligned */
  669.           if (opcode & (1 << 28))
  670.         if (opcode & 0x1)
  671.           the_insn.reloc = LOW2;
  672.         else
  673.           the_insn.reloc = LOW1;
  674.           else
  675.         the_insn.reloc = LOW0;
  676.           goto immediate;
  677.  
  678.         case 'i':        /* 16 bit immediate */
  679.           the_insn.reloc = LOW0;
  680.  
  681.           /*FALLTHROUGH*/
  682.  
  683.         immediate:
  684.           if (*s == ' ')
  685.         s++;
  686.           if (strncmp (s, "ha%", 3) == 0)
  687.         {
  688.           the_insn.highlow = HIGHADJ;
  689.           s += 3;
  690.         }
  691.           else if (strncmp (s, "h%", 2) == 0)
  692.         {
  693.           the_insn.highlow = HIGH;
  694.           s += 2;
  695.         }
  696.           else if (strncmp (s, "l%", 2) == 0)
  697.         {
  698.           the_insn.highlow = PAIR;
  699.           s += 2;
  700.         }
  701.           the_insn.expand = insn->expand;
  702.  
  703.           /* Note that if the getExpression() fails, we will still have
  704.                    created U entries in the symbol table for the 'symbols'
  705.                    in the input string.  Try not to create U symbols for
  706.                    registers, etc. */
  707.  
  708.           if (!getExpression (s))
  709.         {
  710.           s = expr_end;
  711.           continue;
  712.         }
  713.           break;
  714.  
  715.         default:
  716.           as_fatal ("failed sanity check.");
  717.         }
  718.       break;
  719.     }
  720.     error:
  721.       if (match == 0)
  722.     {
  723.       /* Args don't match.  */
  724.       if (&insn[1] - i860_opcodes < NUMOPCODES
  725.           && !strcmp (insn->name, insn[1].name))
  726.         {
  727.           ++insn;
  728.           s = argsStart;
  729.           continue;
  730.         }
  731.       else
  732.         {
  733.           as_bad ("Illegal operands");
  734.           return;
  735.         }
  736.     }
  737.       break;
  738.     }
  739.  
  740.   the_insn.opcode = opcode;
  741. }
  742.  
  743. static int
  744. getExpression (str)
  745.      char *str;
  746. {
  747.   char *save_in;
  748.   segT seg;
  749.  
  750.   save_in = input_line_pointer;
  751.   input_line_pointer = str;
  752.   seg = expression (&the_insn.exp);
  753.   if (seg != absolute_section
  754.       && seg != undefined_section
  755.       && ! SEG_NORMAL (seg))
  756.     {
  757.       the_insn.error = "bad segment";
  758.       expr_end = input_line_pointer;
  759.       input_line_pointer = save_in;
  760.       return 1;
  761.     }
  762.   expr_end = input_line_pointer;
  763.   input_line_pointer = save_in;
  764.   return 0;
  765. }
  766.  
  767.  
  768. /*
  769.   This is identical to the md_atof in m68k.c.  I think this is right,
  770.   but I'm not sure.
  771.  
  772.   Turn a string in input_line_pointer into a floating point constant of type
  773.   type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  774.   emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  775.   */
  776.  
  777. /* Equal to MAX_PRECISION in atof-ieee.c */
  778. #define MAX_LITTLENUMS 6
  779.  
  780. char *
  781. md_atof (type, litP, sizeP)
  782.      char type;
  783.      char *litP;
  784.      int *sizeP;
  785. {
  786.   int prec;
  787.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  788.   LITTLENUM_TYPE *wordP;
  789.   char *t;
  790.   char *atof_ieee ();
  791.  
  792.   switch (type)
  793.     {
  794.  
  795.     case 'f':
  796.     case 'F':
  797.     case 's':
  798.     case 'S':
  799.       prec = 2;
  800.       break;
  801.  
  802.     case 'd':
  803.     case 'D':
  804.     case 'r':
  805.     case 'R':
  806.       prec = 4;
  807.       break;
  808.  
  809.     case 'x':
  810.     case 'X':
  811.       prec = 6;
  812.       break;
  813.  
  814.     case 'p':
  815.     case 'P':
  816.       prec = 6;
  817.       break;
  818.  
  819.     default:
  820.       *sizeP = 0;
  821.       return "Bad call to MD_ATOF()";
  822.     }
  823.   t = atof_ieee (input_line_pointer, type, words);
  824.   if (t)
  825.     input_line_pointer = t;
  826.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  827.   for (wordP = words; prec--;)
  828.     {
  829.       md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
  830.       litP += sizeof (LITTLENUM_TYPE);
  831.     }
  832.   return 0;
  833. }
  834.  
  835. /*
  836.  * Write out big-endian.
  837.  */
  838. void
  839. md_number_to_chars (buf, val, n)
  840.      char *buf;
  841.      valueT val;
  842.      int n;
  843. {
  844.   number_to_chars_bigendian (buf, val, n);
  845. }
  846.  
  847. void
  848. md_number_to_imm (buf, val, n, fixP)
  849.      char *buf;
  850.      long val;
  851.      int n;
  852.      fixS *fixP;
  853. {
  854.   enum reloc_type reloc = fixP->fx_r_type & 0xf;
  855.   enum highlow_type highlow = (fixP->fx_r_type >> 4) & 0x3;
  856.  
  857.   assert (buf);
  858.   assert (n == 4);        /* always on i860 */
  859.  
  860.   switch (highlow)
  861.     {
  862.  
  863.     case HIGHADJ:        /* adjusts the high-order 16-bits */
  864.       if (val & (1 << 15))
  865.     val += (1 << 16);
  866.  
  867.       /*FALLTHROUGH*/
  868.  
  869.     case HIGH:            /* selects the high-order 16-bits */
  870.       val >>= 16;
  871.       break;
  872.  
  873.     case PAIR:            /* selects the low-order 16-bits */
  874.       val = val & 0xffff;
  875.       break;
  876.  
  877.     default:
  878.       break;
  879.     }
  880.  
  881.   switch (reloc)
  882.     {
  883.  
  884.     case BRADDR:        /* br,call,bc,bc.t,bnc,bnc.t w/26-bit immediate */
  885.       if (fixP->fx_pcrel != 1)
  886.     as_bad ("26-bit branch w/o pc relative set: 0x%08x", val);
  887.       val >>= 2;        /* align pcrel offset, see manual */
  888.  
  889.       if (val >= (1 << 25) || val < -(1 << 25))    /* check for overflow */
  890.     as_bad ("26-bit branch offset overflow: 0x%08x", val);
  891.       buf[0] = (buf[0] & 0xfc) | ((val >> 24) & 0x3);
  892.       buf[1] = val >> 16;
  893.       buf[2] = val >> 8;
  894.       buf[3] = val;
  895.       break;
  896.  
  897.     case SPLIT2:        /* 16 bit immediate, 4-byte aligned */
  898.       if (val & 0x3)
  899.     as_bad ("16-bit immediate 4-byte alignment error: 0x%08x", val);
  900.       val &= ~0x3;        /* 4-byte align value */
  901.       /*FALLTHROUGH*/
  902.     case SPLIT1:        /* 16 bit immediate, 2-byte aligned */
  903.       if (val & 0x1)
  904.     as_bad ("16-bit immediate 2-byte alignment error: 0x%08x", val);
  905.       val &= ~0x1;        /* 2-byte align value */
  906.       /*FALLTHROUGH*/
  907.     case SPLIT0:        /* st,bla,bte,btne w/16-bit immediate */
  908.       if (fixP->fx_pcrel == 1)
  909.     val >>= 2;        /* align pcrel offset, see manual */
  910.       /* check for bounds */
  911.       if (highlow != PAIR && (val >= (1 << 16) || val < -(1 << 15)))
  912.     as_bad ("16-bit branch offset overflow: 0x%08x", val);
  913.       buf[1] = (buf[1] & ~0x1f) | ((val >> 11) & 0x1f);
  914.       buf[2] = (buf[2] & ~0x7) | ((val >> 8) & 0x7);
  915.       buf[3] |= val;        /* perserve bottom opcode bits */
  916.       break;
  917.  
  918.     case LOW4:            /* fld,pfld,pst,flush 16-byte aligned */
  919.       if (val & 0xf)
  920.     as_bad ("16-bit immediate 16-byte alignment error: 0x%08x", val);
  921.       val &= ~0xf;        /* 16-byte align value */
  922.       /*FALLTHROUGH*/
  923.     case LOW3:            /* fld,pfld,pst,flush 8-byte aligned */
  924.       if (val & 0x7)
  925.     as_bad ("16-bit immediate 8-byte alignment error: 0x%08x", val);
  926.       val &= ~0x7;        /* 8-byte align value */
  927.       /*FALLTHROUGH*/
  928.     case LOW2:            /* 16 bit immediate, 4-byte aligned */
  929.       if (val & 0x3)
  930.     as_bad ("16-bit immediate 4-byte alignment error: 0x%08x", val);
  931.       val &= ~0x3;        /* 4-byte align value */
  932.       /*FALLTHROUGH*/
  933.     case LOW1:            /* 16 bit immediate, 2-byte aligned */
  934.       if (val & 0x1)
  935.     as_bad ("16-bit immediate 2-byte alignment error: 0x%08x", val);
  936.       val &= ~0x1;        /* 2-byte align value */
  937.       /*FALLTHROUGH*/
  938.     case LOW0:            /* 16 bit immediate, byte aligned */
  939.       /* check for bounds */
  940.       if (highlow != PAIR && (val >= (1 << 16) || val < -(1 << 15)))
  941.     as_bad ("16-bit immediate overflow: 0x%08x", val);
  942.       buf[2] = val >> 8;
  943.       buf[3] |= val;        /* perserve bottom opcode bits */
  944.       break;
  945.  
  946.     case NO_RELOC:
  947.     default:
  948.       as_bad ("bad relocation type: 0x%02x", reloc);
  949.       break;
  950.     }
  951. }
  952.  
  953. /* should never be called for i860 */
  954. void
  955. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  956.      char *ptr;
  957.      addressT from_addr, to_addr;
  958.      fragS *frag;
  959.      symbolS *to_symbol;
  960. {
  961.   as_fatal ("i860_create_short_jmp\n");
  962. }
  963.  
  964. /* should never be called for i860 */
  965. void
  966. md_number_to_disp (buf, val, n)
  967.      char *buf;
  968.      long val;
  969. {
  970.   as_fatal ("md_number_to_disp\n");
  971. }
  972.  
  973. /* should never be called for i860 */
  974. void
  975. md_number_to_field (buf, val, fix)
  976.      char *buf;
  977.      long val;
  978.      void *fix;
  979. {
  980.   as_fatal ("i860_number_to_field\n");
  981. }
  982.  
  983. /* the bit-field entries in the relocation_info struct plays hell
  984.    with the byte-order problems of cross-assembly.  So as a hack,
  985.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  986.    you there. -KWK */
  987. /* on i860: first 4 bytes are normal unsigned long address, next three
  988.    bytes are index, most sig. byte first.  Byte 7 is broken up with
  989.    bit 7 as pcrel, bit 6 as extern, and the lower six bits as
  990.    relocation type (highlow 5-4).  Next 4 bytes are long addend. */
  991. /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
  992. void
  993. md_ri_to_chars (ri_p, ri)
  994.      struct relocation_info *ri_p, ri;
  995. {
  996. #if 0
  997.   unsigned char the_bytes[sizeof (*ri_p)];
  998.  
  999.   /* this is easy */
  1000.   md_number_to_chars (the_bytes, ri.r_address, sizeof (ri.r_address));
  1001.   /* now the fun stuff */
  1002.   the_bytes[4] = (ri.r_index >> 16) & 0x0ff;
  1003.   the_bytes[5] = (ri.r_index >> 8) & 0x0ff;
  1004.   the_bytes[6] = ri.r_index & 0x0ff;
  1005.   the_bytes[7] = ((ri.r_extern << 7) & 0x80) | (0 & 0x60) | (ri.r_type & 0x1F);
  1006.   /* Also easy */
  1007.   md_number_to_chars (&the_bytes[8], ri.r_addend, sizeof (ri.r_addend));
  1008.   /* now put it back where you found it, Junior... */
  1009.   memcpy ((char *) ri_p, the_bytes, sizeof (*ri_p));
  1010. #endif
  1011. }
  1012.  
  1013. /* should never be called for i860 */
  1014. void
  1015. md_convert_frag (headers, fragP)
  1016.      object_headers *headers;
  1017.      register fragS *fragP;
  1018. {
  1019.   as_fatal ("i860_convert_frag\n");
  1020. }
  1021.  
  1022. /* should never be called for i860 */
  1023. void
  1024. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  1025.      char *ptr;
  1026.      addressT from_addr, to_addr;
  1027.      fragS *frag;
  1028.      symbolS *to_symbol;
  1029. {
  1030.   as_fatal ("i860_create_long_jump\n");
  1031. }
  1032.  
  1033. /* should never be called for i860 */
  1034. int
  1035. md_estimate_size_before_relax (fragP, segtype)
  1036.      register fragS *fragP;
  1037.      segT segtype;
  1038. {
  1039.   as_fatal ("i860_estimate_size_before_relax\n");
  1040. }
  1041.  
  1042. /* for debugging only, must match enum reloc_type */
  1043. static char *Reloc[] =
  1044. {
  1045.   "NO_RELOC",
  1046.   "BRADDR",
  1047.   "LOW0",
  1048.   "LOW1",
  1049.   "LOW2",
  1050.   "LOW3",
  1051.   "LOW4",
  1052.   "SPLIT0",
  1053.   "SPLIT1",
  1054.   "SPLIT2",
  1055.   "RELOC_32",
  1056. };
  1057. static char *Highlow[] =
  1058. {
  1059.   "NO_SPEC",
  1060.   "PAIR",
  1061.   "HIGH",
  1062.   "HIGHADJ",
  1063. };
  1064. static void
  1065. print_insn (insn)
  1066.      struct i860_it *insn;
  1067. {
  1068.   if (insn->error)
  1069.     {
  1070.       fprintf (stderr, "ERROR: %s\n");
  1071.     }
  1072.   fprintf (stderr, "opcode=0x%08x\t", insn->opcode);
  1073.   fprintf (stderr, "expand=0x%08x\t", insn->expand);
  1074.   fprintf (stderr, "reloc = %s\t", Reloc[insn->reloc]);
  1075.   fprintf (stderr, "highlow = %s\n", Highlow[insn->highlow]);
  1076.   fprintf (stderr, "exp =  {\n");
  1077.   fprintf (stderr, "\t\tX_add_symbol = %s\n",
  1078.        insn->exp.X_add_symbol ?
  1079.        (S_GET_NAME (insn->exp.X_add_symbol) ?
  1080.         S_GET_NAME (insn->exp.X_add_symbol) : "???") : "0");
  1081.   fprintf (stderr, "\t\tX_op_symbol = %s\n",
  1082.        insn->exp.X_op_symbol ?
  1083.        (S_GET_NAME (insn->exp.X_op_symbol) ?
  1084.         S_GET_NAME (insn->exp.X_op_symbol) : "???") : "0");
  1085.   fprintf (stderr, "\t\tX_add_number = %d\n",
  1086.        insn->exp.X_add_number);
  1087.   fprintf (stderr, "}\n");
  1088. }
  1089.  
  1090. CONST char *md_shortopts = "";
  1091. struct option md_longopts[] = {
  1092.   {NULL, no_argument, NULL, 0}
  1093. };
  1094. size_t md_longopts_size = sizeof(md_longopts);
  1095.  
  1096. int
  1097. md_parse_option (c, arg)
  1098.      int c;
  1099.      char *arg;
  1100. {
  1101.   return 0;
  1102. }
  1103.  
  1104. void
  1105. md_show_usage (stream)
  1106.      FILE *stream;
  1107. {
  1108. }
  1109.  
  1110. #ifdef comment
  1111. /*
  1112.  * I860 relocations are completely different, so it needs
  1113.  * this machine dependent routine to emit them.
  1114.  */
  1115. void
  1116. emit_machine_reloc (fixP, segment_address_in_file)
  1117.      register fixS *fixP;
  1118.      relax_addressT segment_address_in_file;
  1119. {
  1120.   struct reloc_info_i860 ri;
  1121.   register symbolS *symbolP;
  1122.   extern char *next_object_file_charP;
  1123.   long add_number;
  1124.  
  1125.   memset ((char *) &ri, '\0', sizeof (ri));
  1126.   for (; fixP; fixP = fixP->fx_next)
  1127.     {
  1128.  
  1129.       if (fixP->fx_r_type & ~0x3f)
  1130.     {
  1131.       as_fatal ("fixP->fx_r_type = %d\n", fixP->fx_r_type);
  1132.     }
  1133.       ri.r_pcrel = fixP->fx_pcrel;
  1134.       ri.r_type = fixP->fx_r_type;
  1135.  
  1136.       if ((symbolP = fixP->fx_addsy) != NULL)
  1137.     {
  1138.       ri.r_address = fixP->fx_frag->fr_address +
  1139.         fixP->fx_where - segment_address_in_file;
  1140.       if (!S_IS_DEFINED (symbolP))
  1141.         {
  1142.           ri.r_extern = 1;
  1143.           ri.r_symbolnum = symbolP->sy_number;
  1144.         }
  1145.       else
  1146.         {
  1147.           ri.r_extern = 0;
  1148.           ri.r_symbolnum = S_GET_TYPE (symbolP);
  1149.         }
  1150.       if (symbolP && symbolP->sy_frag)
  1151.         {
  1152.           ri.r_addend = symbolP->sy_frag->fr_address;
  1153.         }
  1154.       ri.r_type = fixP->fx_r_type;
  1155.       if (fixP->fx_pcrel)
  1156.         {
  1157.           /* preserve actual offset vs. pc + 4 */
  1158.           ri.r_addend -= (ri.r_address + 4);
  1159.         }
  1160.       else
  1161.         {
  1162.           ri.r_addend = fixP->fx_addnumber;
  1163.         }
  1164.  
  1165.       md_ri_to_chars ((char *) &ri, ri);
  1166.       append (&next_object_file_charP, (char *) &ri, sizeof (ri));
  1167.     }
  1168.     }
  1169. }
  1170.  
  1171. #endif /* comment */
  1172.  
  1173. #ifdef OBJ_AOUT
  1174.  
  1175. /* on i860: first 4 bytes are normal unsigned long address, next three
  1176.    bytes are index, most sig. byte first.  Byte 7 is broken up with
  1177.    bit 7 as pcrel, bit 6 as extern, and the lower six bits as
  1178.    relocation type (highlow 5-4).  Next 4 bytes are long addend. */
  1179.  
  1180. void
  1181. tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
  1182.      char *where;
  1183.      fixS *fixP;
  1184.      relax_addressT segment_address_in_file;
  1185. {
  1186.   long r_index;
  1187.   long r_extern;
  1188.   long r_addend = 0;
  1189.   long r_address;
  1190.  
  1191.   know (fixP->fx_addsy);
  1192.   know (!(fixP->fx_r_type & ~0x3f));
  1193.  
  1194.   if (!S_IS_DEFINED (fixP->fx_addsy))
  1195.     {
  1196.       r_extern = 1;
  1197.       r_index = fixP->fx_addsy->sy_number;
  1198.     }
  1199.   else
  1200.     {
  1201.       r_extern = 0;
  1202.       r_index = S_GET_TYPE (fixP->fx_addsy);
  1203.     }
  1204.  
  1205.   md_number_to_chars (where,
  1206.               r_address = fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
  1207.               4);
  1208.  
  1209.   where[4] = (r_index >> 16) & 0x0ff;
  1210.   where[5] = (r_index >> 8) & 0x0ff;
  1211.   where[6] = r_index & 0x0ff;
  1212.   where[7] = (((fixP->fx_pcrel << 7) & 0x80)
  1213.           | ((r_extern << 6) & 0x40)
  1214.           | (fixP->fx_r_type & 0x3F));
  1215.  
  1216.   if (fixP->fx_addsy->sy_frag)
  1217.     {
  1218.       r_addend = fixP->fx_addsy->sy_frag->fr_address;
  1219.     }
  1220.  
  1221.   if (fixP->fx_pcrel)
  1222.     {
  1223.       /* preserve actual offset vs. pc + 4 */
  1224.       r_addend -= (r_address + 4);
  1225.     }
  1226.   else
  1227.     {
  1228.       r_addend = fixP->fx_addnumber;
  1229.     }
  1230.  
  1231.   md_number_to_chars (&where[8], r_addend, 4);
  1232. }
  1233.  
  1234. #endif /* OBJ_AOUT */
  1235.  
  1236. /* Parse an operand that is machine-specific.
  1237.    We just return without modifying the expression if we have nothing
  1238.    to do.  */
  1239.  
  1240. /* ARGSUSED */
  1241. void
  1242. md_operand (expressionP)
  1243.      expressionS *expressionP;
  1244. {
  1245. }
  1246.  
  1247. /* We have no need to default values of symbols.  */
  1248.  
  1249. /* ARGSUSED */
  1250. symbolS *
  1251. md_undefined_symbol (name)
  1252.      char *name;
  1253. {
  1254.   return 0;
  1255. }
  1256.  
  1257. /* Round up a section size to the appropriate boundary.  */
  1258. valueT
  1259. md_section_align (segment, size)
  1260.      segT segment;
  1261.      valueT size;
  1262. {
  1263.   return size;            /* Byte alignment is fine */
  1264. }
  1265.  
  1266. /* Exactly what point is a PC-relative offset relative TO?
  1267.    On the i860, they're relative to the address of the offset, plus
  1268.    its size. (??? Is this right?  FIXME-SOON!) */
  1269. long
  1270. md_pcrel_from (fixP)
  1271.      fixS *fixP;
  1272. {
  1273.   return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
  1274. }
  1275.  
  1276. void
  1277. md_apply_fix (fixP, val)
  1278.      fixS *fixP;
  1279.      long val;
  1280. {
  1281.   char *place = fixP->fx_where + fixP->fx_frag->fr_literal;
  1282.  
  1283.   /* looks to me like i860 never has bit fixes. Let's see. xoxorich. */
  1284.   know (fixP->fx_bit_fixP == NULL);
  1285.   if (!fixP->fx_bit_fixP)
  1286.     {
  1287.  
  1288.       /* also looks like fx_im_disp is always 0.  Let's see.  xoxorich. */
  1289.       know (fixP->fx_im_disp == 0);
  1290.       switch (fixP->fx_im_disp)
  1291.     {
  1292.     case 0:
  1293.       fixP->fx_addnumber = val;
  1294.       md_number_to_imm (place, val, fixP->fx_size, fixP);
  1295.       break;
  1296.     case 1:
  1297.       md_number_to_disp (place,
  1298.              fixP->fx_pcrel ? val + fixP->fx_pcrel_adjust : val,
  1299.                  fixP->fx_size);
  1300.       break;
  1301.     case 2:        /* fix requested for .long .word etc */
  1302.       md_number_to_chars (place, val, fixP->fx_size);
  1303.       break;
  1304.     default:
  1305.       as_fatal ("Internal error in md_apply_fix() in file \"%s\"", __FILE__);
  1306.     }            /* OVE: maybe one ought to put _imm _disp _chars in one md-func */
  1307.     }
  1308.   else
  1309.     {
  1310.       md_number_to_field (place, val, fixP->fx_bit_fixP);
  1311.     }
  1312. }
  1313.  
  1314. /*
  1315.  * Local Variables:
  1316.  * fill-column: 131
  1317.  * comment-column: 0
  1318.  * End:
  1319.  */
  1320.  
  1321. /* end of tc-i860.c */
  1322.